<template>
  <div class="new_auction_Warehouse">
    <c-title :hide="false" :text="'我的仓库'"></c-title>
    <van-tabs v-model="active" title-active-color="#126F46" color="#126F46" @change="tabChange">
      <van-tab title="待提商品" name="1" :title-style="active == '1' ? 'color:#126F46;font-weight: bold;font-size: 1.13rem;' : 'color:#000000;font-size: 1rem;font-weight: 400;'"></van-tab>
      <van-tab title="已提商品" name="2" :title-style="active == '2' ? 'color:#126F46;font-weight: bold;font-size: 1.13rem;' : 'color:#000000;font-size: 1rem;font-weight: 400;'"></van-tab>
      <van-tab title="正在参拍" name="3" :title-style="active == '3' ? 'color:#126F46;font-weight: bold;font-size: 1.13rem;' : 'color:#000000;font-size: 1rem;font-weight: 400;'"></van-tab>
    </van-tabs>
    <div v-for="(item, ind) in list" :key="ind">
      <bidding :detailsTag="checkDetailsTag" :infoData="item" @pickUp_new="pickUp_newChild" @pickUp="pickUpChild" @settle_handle="settle_handle"></bidding>
    </div>
    <option_popup
      v-if="selectItem"
      :isPick_new="isPick_new"
      :isPick="isPick"
      :showPopup="show"
      :item="selectItem"
      @pickUp_new="pickUp_new_popup"
      @pickUp="pickUpChild_popup"
      @closePopup="closePopup"
    ></option_popup>
  </div>
</template>
<script>
import bidding from "./components/bidding.vue";
import { scrollMixin } from "utils/mixin";
import option_popup from "./components/optionPopup.vue";
import { Dialog } from "vant";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      active: "1",
      show: false,
      selectItem: null,
      list: [],
      isLoadMore: true,
      isPick: false,
      isPick_new: false,
      page: 1,
      total_page: 0
    };
  },
  activated() {
    this.active = "1";
    this.init();
    this.getData();
  },
  computed: {
    checkDetailsTag() {
      if (this.active == "1") {
        return "mentioned";
      } else if (this.active == "2") {
        return "Readmentioned";
      } else {
        return "usable";
      }
    }
  },
  methods: {
    pickUp_new_popup(e) {
      let json = {
        new_auction_activity_id: e.id,
        new_auction_pick_num: e.value
      };
      this.$router.push(this.fun.getUrl("new_auction_order", json, { tag: "new_auction_mentioned" }));
      this.closePopup();
      this.init();
      this.getData();
    },
    tapActive(e) {
      // 待提跟已提都不可点击
      if (this.active == 2 || this.active == 1) return;
      this.$router.push(this.fun.getUrl("new_auction_detail", { id: e.activity_id }));
    },
    closePopup() {
      this.show = false;
      this.isPick = false;
      this.isPick_new = false;
      this.selectItem = null;
    },
    async pickUpChild_popup(e) {
      let json = {
        new_auction_id: e.id,
        new_auction_pick_num: e.value
      };
      this.$router.push(this.fun.getUrl("new_auction_order", json, { tag: "new_auction" }));
      this.closePopup();
      this.init();
      this.getData();
    },
    pickUp_newChild(e) {
      this.show = true;
      this.isPick_new = true;
      this.selectItem = e.item;
    },
    async pickUpChild(e) {
      this.show = true;
      this.isPick = true;
      this.selectItem = e.item;
    },
    settle_handle({ id, data }) {
      console.log(id, data, "结算====");
      Dialog.confirm({
        message: `是否确认退拍${data.has_one_goods.title}*${data.settle_count}个`
      })
        .then(() => {
          $http.post("plugin.new-auction.frontend.auction.settle", { id }, "").then(({ result, msg }) => {
            this.$toast(msg);
            this.init();
            this.getData();
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    init() {
      this.list = [];
      this.page = 1;
      this.total_page = 0;
      this.isLoadMore = true;
    },
    tabChange() {
      this.init();
      this.getData();
    },
    async getData() {
      let urlstr = "";
      let json = {};
      if (this.active == "1") {
        urlstr = "plugin.new-auction.frontend.activity.activityGoodsList";
      } else if (this.active == "2") {
        urlstr = "plugin.new-auction.frontend.order.extraList";
      } else if (this.active == "3") {
        urlstr = "plugin.new-auction.frontend.auction";
        json.is_usable = 1;
      }
      let { msg, result, data } = await $http.post(urlstr, json, ".");
      if (result) {
        console.log(data);
        this.list = data.data;
        this.total_page = data.last_page;
        this.isLoadMore = true;
      } else {
        this.$toast(msg);
      }
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false;
      if (this.page >= this.total_page) {
        return;
      } else {
        let urlstr = "";
        this.page += 1;
        let json = {
          page: this.page
        };
        if (this.active == "1") {
          urlstr = "plugin.new-auction.frontend.activity.activityGoodsList";
        } else if (this.active == "2") {
          urlstr = "plugin.new-auction.frontend.order.extraList";
        } else if (this.active == "3") {
          urlstr = "plugin.new-auction.frontend.auction";
          json.is_usable = 1;
        }
        let { msg, result, data } = await $http.post(urlstr, json, ".");
        this.isLoadMore = true;
        if (result) {
          console.log(data);
          this.list = this.list.concat(data.data);
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$toast(msg);
        }
      }
    }
  },
  components: { bidding, option_popup }
};
</script>
<style lang="scss" scoped></style>
